import Handler from "./Handler";

const { ccclass, property } = cc._decorator;

@ccclass
export default class EventHandler extends Handler {
    _dispatcher = null;
    _type = null;

    constructor(t, a, o, i?) {
        super(t, a, o, i)
    }

    recover() {
        if (this._id > 0) {
            this._id = 0;
            EventHandler._pool.push(this.clear());
        }
    }

    register(e, t) {
        this._dispatcher = e;
        this._type = t;
    }

    check(e, t) {
        return !(this._dispatcher && this._dispatcher !== e || this._type && this._type !== t);
    }

    static create(e, t, a, o): EventHandler {
        void 0 === a && (a = null);
        void 0 === o && (o = true);
        return EventHandler._pool.length ? EventHandler._pool.pop().setTo(e, t, a, o) : new EventHandler(e, t, a, o);
    }
}
